import * as apiService from '@/services/api.js';

import store from '@/store';

/**
 * 财务总报表
 *
 */
const fundReportApi = async ({
    date,
    page,
    size
}) => {
    const [result, data] = await apiService.post(`${consts.PROXY_PREV}/proxy/fundReport`, {
        proxyName: store.getters.username,
        stime: _.result(date, '[0]'),
        etime: _.result(date, '[1]'),
        page,
        size,
    });

    return [result, data];
};

/**
 * 游戏输赢报表
 */
const gameReportApi = async ({
    date,
    username,
    page,
    size
}) => {
    const [result, data] = await apiService.post(`${consts.PROXY_PREV}/proxy/gameReport`, {
        proxyName: store.getters.username,
        userName: username,
        stime: _.result(date, '[0]'),
        etime: _.result(date, '[1]'),
        page,
        size,
    });

    return [result, data];
};

/**
 * 存提明细报表
 */
const rechargeWithdrawReportApi = async ({
    date,
    page,
    size
}) => {
    const [result, data] = await apiService.post(`${consts.PROXY_PREV}/proxy/rechargeWithdrawReport`, {
        proxyName: store.getters.username,
        stime: _.result(date, '[0]'),
        etime: _.result(date, '[1]'),
        page,
        size,
    });

    return [result, data];
};

/**
 * 红利返水报表
 */
const bonusRebateReportApi = async ({
    date,
    page,
    size
}) => {
    const [result, data] = await apiService.post(`${consts.PROXY_PREV}/proxy/bonusRebateReport`, {
        proxyName: store.getters.username,
        stime: _.result(date, '[0]'),
        etime: _.result(date, '[1]'),
        page,
        size,
    });

    return [result, data];
};
/**
 * 佣金报表
 */
const commissionReportApi = async () => {
    // const [result,data] = await apiService.get(`http://report.mrball.com.cn/proxy/commissionReport`, {
    const [result, data] = await apiService.post(`${consts.PROXY_PREV}/proxy/commissionReport`, {
        proxyId: store.getters.userId,
    });
    return [result, data];
};

/**
 * 会员上分记录
 */
const upAmountApi = async ({
        date,
        username,
        page,
        size,
        optType
    }) => {
        // const [result,data] = await apiService.post(`${consts.PROXY_PREV}/proxy/upAmount`, {
        const [result, data] = await apiService.post(`/gl/proxy/credit/upAmount/list/report`, {
            proxyId: store.getters.userId,
            userName : username,
            startTime: date ? _.toTime(date[0]) : undefined,
            endTime: date ? _.toTime(date[1]) : undefined,
            page,
            size,
            optType
        });

        return [result, data];
};

/**
 * 代理上分记录
 */
const upAmountGrant = async ({
    date,
    username,
    page,
    size
}) => {
    const [result, data] = await apiService.post(`${consts.PROXY_PREV}/proxy/upAmountGrant`, {
        proxyId: store.getters.userId,
        userName: username,
        stime: _.result(date, '[0]'),
        etime: _.result(date, '[1]'),
        page,
        size,
    });

    return [result, data];
};

/**
 * 会员首存报表
 */
const firstRechargeApi = async ({
    date,
    username,
    status,
    page,
    size
}) => {
    const [result, data] = await apiService.post(`${consts.PROXY_PREV}/proxy/firstRechargeReport`, {
        proxyId: store.getters.userId,
        userName: username,
        stime: _.result(date, '[0]'),
        etime: _.result(date, '[1]'),
        status,
        page,
        size,
    });

    return [result, data];
};

/**
 * 投注详细
 */
const bettingDetailApi = async ({
    date,
    gamePlatformId,
    username,
    page,
    size,
    tradeNo,
    betWays
}) => {
    // const [result,data] = await apiService.get(`http://report.mrball.com.cn/proxy/betDetail`, {
    const [result, data] = await apiService.post(`${consts.PROXY_PREV}/proxy/betDetail`, {
        proxyName: store.getters.username,
        // proxyName: 'admin',
        userName: username,
        gamePlatformId,
        stime: _.result(date, '[0]'),
        etime: _.result(date, '[1]'),
        page,
        size,
        tradeNo,
        betWays
    });

    return [result, data];
};

/**
 * 投注详情 -- 按照用户分类
 * @param date
 * @param gamePlatformId
 * @param username
 * @param cursor
 * @param size
 * @param betWays
 * @returns {Promise<*[]>}
 */

const bettingDetailByUserApi = async ({
    date,
    gamePlatformId,
    username,
    cursor,
    size,
    betWays
}) => {
    // const [result,data] = await apiService.get(`http://report.mrball.com.cn/proxy/betDetail`, {
    const [result, data] = await apiService.post(`${consts.PROXY_PREV}/proxy/betDetailByUser`, {
        proxyName: store.getters.username,
        // proxyName: 'admin',
        userName: username,
        gamePlatformId,
        stime: _.result(date, '[0]'),
        etime: _.result(date, '[1]'),
        cursor,
        size,
        betWays
    });

    return [result, data];
};

/**
 * 返水详细
 */
const rebateDetailApi = async ({
    date,
    username,
    cursor,
    size
}) => {
    const [result, data] = await apiService.post(`${consts.PROXY_PREV}/proxy/rebateDetail`, {
        proxyName: store.getters.username,
        userName: username,
        stime: _.result(date, '[0]'),
        etime: _.result(date, '[1]'),
        cursor,
        size
    });

    return [result, data];
};

/**
 * 存款详细
 */
const rechargeDetailApi = async ({
    date,
    username,
    page,
    size
}) => {
    const [result, data] = await apiService.post(`${consts.PROXY_PREV}/proxy/rechargeDetail`, {
        proxyName: store.getters.username,
        userName: username,
        stime: _.result(date, '[0]'),
        etime: _.result(date, '[1]'),
        page,
        size,
    });

    return [result, data];
};

/**
 * 提款详细
 */
const withdrawDetailApi = async ({
        date,
        username,
        page,
        size
    }) => {
    // const [result,data] = await apiService.get(`http://report.mrball.com.cn/proxy/withdrawDetail`, {
    const [result, data] = await apiService.post(`${consts.PROXY_PREV}/proxy/withdrawDetail`, {
        proxyName: store.getters.username,
        // proxyName: 'admin',
        userName: username,
        stime: _.result(date, '[0]'),
        etime: _.result(date, '[1]'),
        page,
        size,
    });

    return [result, data];
};

/**
 * 红利详细
 */
const bonusDetailApi = async ({
    date,
    username,
    cursor,
    size
}) => {
    const [result, data] = await apiService.post(`${consts.PROXY_PREV}/proxy/bonusDetail`, {
        proxyName: store.getters.username,
        userName: username,
        stime: _.result(date, '[0]'),
        etime: _.result(date, '[1]'),
        cursor,
        size
    });

    return [result, data];
};

/**
 * 红利返水详细
 */
const bonusRebateDetailApi = async ({
    date,
    username
}) => {
    const [result, data] = await apiService.post(`${consts.PROXY_PREV}/proxy/bonusRebateDetail`, {
        proxyName: store.getters.username,
        userName: username,
        stime: _.result(date, '[0]'),
        etime: _.result(date, '[1]'),
    });

    return [result, data];
};

/**
 * 下级代理佣金 (已不用)
 */
const subCommissionApi = async ({
    settleDate
}) => {
    const [result, data] = await apiService.post(`${consts.PROXY_PREV}/proxy/subCommission`, {
        proxyId: store.getters.userId,
        settleDate,
    });

    return [result, data];
};

/**
 * 下级代理佣金
 * @param settleDate
 * @param commMode
 * @returns {Promise<*[]>}
 */
const commissionSubLevelApi = async ({
    settleDate,
    commMode = 1
}) => {
    const [result, data] = await apiService.post(`/gl/proxy/commission/sub/level`, {
        proxyId: store.getters.userId,
        settleDate,
        commMode,
    });

    return [result, data];
};

/**
 * 会员佣金
 */
const memberCommissionApi = async ({
    settleDate
}) => {
    const [result, data] = await apiService.post(`${consts.PROXY_PREV}/proxy/memberCommission`, {
        proxyId: store.getters.userId,
        settleDate,
    });

    return [result, data];
};

/**
 * 会员佣金详细
 */
const memberCommissionDetailApi = async ({
    settleDate,
    username
}) => {
    const [result, data] = await apiService.post(`${consts.PROXY_PREV}/proxy/memberCommissionDetail`, {
        // const [result,data] = await apiService.post(`${consts.PROXY_PREV}/proxy/memberCommissionDetail`, {
        proxyId: store.getters.userId,
        userName: username,
        settleDate,
    });

    return [result, data];
};

/**
 * 会员充提手续费详细
 * tradeType 0全部,1存款,2提款
 */
const memberFeeDetailApi = async ({
    settleDate,
    username,
    tradeType = 0,
    page,
    size,
}) => {
    const [result, data] = await apiService.post(`${consts.PROXY_PREV}/proxy/rechargeWithdrawFeeDetail`, {
        proxyId: store.getters.userId,
        userName: username,
        tradeType,
        stime: moment(settleDate).startOf('month').valueOf(),
        etime: moment(settleDate).endOf('month').valueOf(),
        page,
        size,
    });

    return [result, data];
};

/**
 * 代理佣金详细
 */
const proxySubCommissionDetailApi = async ({
    level, username, page, size, settleDate, commMode = 1 }) => {
    const [result, data] = await apiService.post(`${consts.PROXY_PREV}/proxy/subCommissionDetail`, {
        proxyId: store.getters.userId,
        userName: username,
        level,
        page,
        size,
        settleDate,
        commMode,
    });

    return [result, data];
};

/**
 * 获取代理下级节点树
 * @param ownerId
 * @param settleDate
 * @param nodeId
 * @param commMode
 * @returns {Promise<*[]>}
 */
const commissionSubDetailTreeApi = async ({ ownerId, settleDate, nodeId }) => {
    const [result, data] = await apiService.post(`/gl/proxy/commission/sub/detail/tree`, {
        ownerId: store.getters.userId,
        settleDate,
        nodeId,
    });

    return [result, data];
};

/**
 * 确认申请清算上分额度
 */
const sureEmptyAmount = async ({ amount, proxyId}) => {
    const [result, data] = await apiService.post(`/gl/proxy/credit/creditClear/apply`, {
        amount,
        proxyId
    });

    return [result, data];
};


export {
    fundReportApi,
    gameReportApi,
    rechargeWithdrawReportApi,
    bonusRebateReportApi,
    commissionReportApi,
    upAmountApi,
    upAmountGrant,
    firstRechargeApi,
    bettingDetailApi,
    rebateDetailApi,
    bonusDetailApi,
    rechargeDetailApi,
    withdrawDetailApi,
    subCommissionApi,
    memberCommissionApi,
    memberCommissionDetailApi,
    proxySubCommissionDetailApi,
    bonusRebateDetailApi,
    memberFeeDetailApi,
    commissionSubLevelApi,
    commissionSubDetailTreeApi,
    bettingDetailByUserApi,
    sureEmptyAmount
};